package com.wjgl.service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.wjgl.dao.DB;

public class SqlHelper {
	private Connection conn = null;
	private PreparedStatement pstmt = null;
	private ResultSet rs = null;
	
	public void excuteSql(String sql){
	
		conn = new DB().getConn();
		try {
			pstmt = conn.prepareStatement(sql);
			int n = pstmt.executeUpdate();
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			this.close();
			e.printStackTrace();
		}
		this.close();
	}
	
	
	private void close(){
		try {
			if(rs!=null){
				rs.close();
				rs = null;
			}
			if(pstmt != null){
				pstmt.close();
				pstmt = null;
			}
			if(!conn.isClosed()){
				conn.close();
				conn = null;
			}
				
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
}
